package com.hutianao.gqgl.verify.control;

import com.hutianao.gqgl.spring.control.BaseController;
import com.hutianao.gqgl.verify.service.VerifyService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/Verify")
public class VerifyController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private VerifyService VerifyService;
    /**
     * 获取验证码
     * @return
     */
    @RequestMapping("/getLoginVfcCode/{fileName}")
    @ResponseBody
    public ResponseEntity<byte[]> getLoginVfcCode(HttpServletRequest request){

        ResponseEntity<byte[]> responseEntity = VerifyService.getLoginVfcCode(request);
        return  responseEntity;
    }

    @RequestMapping("/authVfcCode")
    @ResponseBody
    public String authVfcCode (HttpServletRequest request,@RequestParam("vfcCode") String vfcCode){
        logger.info("vfcCode:" + vfcCode);
        boolean rstB = VerifyService.authVfcCode(vfcCode,request);
        if(rstB){
            return jsonSuccess("login.auth.vfc.code.success");
        }
        return jsonFail("login.auth.vfc.code.fail");
        //login.auth.vfc.code.fail
    }


}
